package com.didi.gulimall.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 10626
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket productApi() {
        ParameterBuilder headerParams = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        //header中name默认都为小写
        headerParams.name("roletype").description("user roletype")
                .modelRef(new ModelRef("string")).parameterType("header")
                //header中的ticket参数非必填，传空也可以
                .required(false).build();
        pars.add(headerParams.build());
        headerParams.name("userid").description("userid").build();
        pars.add(headerParams.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.didi.gulimall"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars);

    }


    private ApiInfo apiInfo() {
        return  new ApiInfoBuilder()
                .title("order 接口文档")
                .version("2.0")
                .contact(new Contact("test", "", "test@pg.com.cn"))
                .build();
    }


}
